<template>
    <div>
<h2>添加机构</h2>
<table class="table">
    <tbody>
        <tr>
            <td>机构名称</td>
            <td>
                <input type="text"  v-model="model.JiGouName" >
            </td>
        </tr>


        <tr>
            <td>机构特色</td>
            <td>
              <select v-model="model.TeSe">
              <option  :value="-1">请选择</option>
              <option  value="24小时服务">24小时服务</option>
              <option  value="免费停车">免费停车</option>
              <option  value="免费护理">免费护理</option>
              <option  value="免费早餐">免费早餐</option>
              </select>
            </td>
        </tr>



        <tr>
            <td>时间</td>
            <td>
                <input type="date"  v-model="model.CreateTime" >
            </td>
        </tr>



        <tr>
            <td>机构地址</td>
            <td>
                <input type="text"   v-model="model.Adder" >
            </td>
        </tr>



        <tr>
            <td>联系电话</td>
            <td>
                <input type="text"   v-model="model.Phone"  maxlength="11">
            </td>
        </tr>



        <tr>
            <td>是否发布</td>
            <td>
                <input type="radio" name="state"  v-model="model.State"   value="1">是
                <input type="radio" name="state"  v-model="model.State"  value="0">否
            </td>
        </tr>



        <tr>
            <td>机构详情</td>
            <td>
              <textarea cols="35" rows="5" v-model="model.XiangQing"></textarea>
            </td>
        </tr>




        <tr>
            <td></td>
            <td>
                <input type="button" value="添加" class="btn  btn-success" @click="ok">
            </td>
        </tr>
    </tbody>
</table>



    </div>
</template>

<script setup lang="ts">
import { ref,reactive } from 'vue';
import { useRoute,useRouter } from 'vue-router';
import axios from 'axios';
const route=useRoute();
const router=useRouter();


//定义变量
let model=reactive({
    
  "JiGouName": '',
  "TeSe":  '',
  "CreateTime":  '',
  "Adder":  '',
  "Phone":  '',
  "State":  1,
  "XiangQing":'',
  })
  



//添加
const ok=()=>{


if(model.JiGouName==""){
alert('机构名称不能为空');
return;
}

if(model.TeSe==""){
alert('机构特色不能为空');
return;
}


if(model.CreateTime==""){
alert('机构时间不能为空');
return;
}



if(model.Adder==""){
alert('机构地址不能为空');
return;
}



if(model.Phone==""){
alert('机构联系方式不能为空');
return;
}



if(model.XiangQing==""){
alert('机构详情不能为空');
return;
}



axios({
url:'https://localhost:7009/api/User/JiGouAdd',
method:'post',
data:model,
})


.then((res)=>{
console.log(res);
if(res.data>0){
    alert('添加成功');
    router.push('/JiGouList')
    return;
}
else {
    alert('添加失败');
    return;
}




})




.catch((ree)=>{
console.log(ree);
})






}


</script>

<style scoped>

</style>